package com.yidi.system.service.imp;

import com.yidi.system.domain.SysUserPost;
import com.yidi.system.repository.SysUserPostRepository;
import com.yidi.system.service.SysUserPostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author ：Xn
 * @ClassName: SysUserPostServiceImpl
 * @date ：2021-10-19 14:21
 * @describe ：
 */
@Service
public class SysUserPostServiceImpl implements SysUserPostService {

    @Autowired
    private SysUserPostRepository sysUserPostRepository;

    /**
     * 通过用户ID删除用户和岗位关联
     *
     * @param userId 用户ID
     * @return 结果
     */
    @Override
    public void deleteUserPostByUserId(Long userId) {

        sysUserPostRepository.deleteUserPostByUserId(userId);
    }

    /**
     * 批量新增用户岗位信息
     *
     * @param userPostList 用户角色列表
     * @return 结果
     */
    @Override
    public void batchUserPost(List<SysUserPost> userPostList) {
        for(SysUserPost up : userPostList) {
            sysUserPostRepository.save(up);
        }
    }

    @Override
    public void deleteUserPost(Long[] userIds){
        for(Long id : userIds){
            deleteUserPostByUserId(id);        }
    }
}
